home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / HPACK78S.ZIP / filehdr.h < prev    next >
C/C++ Source or Header  |  1992-11-19  |  8KB  |  189 lines

  1. /****************************************************************************
  2. *                                                                            *
  3. *                            HPACK Multi-System Archiver                        *
  4. *                            ===========================                        *
  5. *                                                                            *
  6. *                         Archive Directory Structure Header                    *
  7. *                            FILEHDR.H  Updated 15/09/91                        *
  8. *                                                                            *
  9. * This program is protected by copyright and as such any use or copying of    *
  10. *  this code for your own purposes directly or indirectly is highly uncool    *
  11. *                      and if you do so there will be....trubble.                *
  12. *                 And remember: We know where your kids go to school.            *
  13. *                                                                            *
  14. *        Copyright 1989 - 1991  Peter C.Gutmann.  All rights reserved        *
  15. *                                                                            *
  16. ****************************************************************************/
  17.  
  18. #ifndef _FILEHDR_DEFINED
  19.  
  20. #define _FILEHDR_DEFINED
  21.  
  22. /****************************************************************************
  23. *                                                                            *
  24. *                    File and Directory Information Bitfields                *
  25. *                                                                            *
  26. ****************************************************************************/
  27.  
  28. /* The bitfields are handled via bit twiddling of a WORD/BYTE for portability
  29.    reasons.
  30.  
  31. typedef struct {
  32.                unsigned origLen       : 1;    \* fileLen field WORD/LONG bit *\
  33.                unsigned coprLen       : 1;    \* dataLen field WORD/LONG bit *\
  34.                unsigned otherLen   : 2;    \* dirIndex/extraLen field length *\
  35.                unsigned isSpecial  : 1; \* Whether this is type SPECIAL hdr *\
  36.                unsigned hasExtra   : 1;    \* Whether extra info is attached *\
  37.                unsigned isText       : 1; \* Whether this is a text file *\
  38.                unsigned dataFormat : 3; \* Storage format type *\
  39.                unsigned systemType : 6;    \* The system the archive was created on *\
  40.                } ARCHIVEINFO;
  41.  
  42. typedef struct {
  43.                unsigned otherLen   : 2; \* parentIndex/dataLen field length *\
  44.                unsigned isSpecial  : 1; \* Whether this is a type SPECIAL header *\
  45.                unsigned linked     : 1; \* Whether this is a linked header *\
  46.                unsigned unicode    : 1; \* Whether dir.name is Unicode *\
  47.                unsigned spare      : 3; \* Reserved for future use *\
  48.                } DIRINFO; */
  49.  
  50. /* The values for the ARCHIVEINFO bitfield */
  51.  
  52. #define ARCH_ORIG_LEN    0x8000    /* fileLen field WORD/LONG flag */
  53. #define ARCH_COPR_LEN    0x4000    /* dataLen field WORD/LONG flag */
  54. #define ARCH_OTHER_LEN    0x3000    /* dirIndex/auxLen field length */
  55. #define ARCH_OTHER_HI    0x2000    /* High bit of ARCH_OTHER_LEN */
  56. #define ARCH_OTHER_LO    0x1000    /* Low bit of ARCH_OTHER_LEN */
  57. #define ARCH_SPECIAL    0x0800    /* Whether this is type SPECIAL header */
  58. #define ARCH_EXTRAINFO    0x0400    /* Whether there is extra data attached */
  59. #define ARCH_ISTEXT        0x0200    /* Whether this is a text file */
  60. #define ARCH_STORAGE    0x01C0    /* Storage type */
  61. #define ARCH_SYSTEM        0x003F    /* The system the archive was created on */
  62.  
  63. /* The values for the DIRINFO bitfield */
  64.  
  65. #define DIR_OTHER_LEN    0xC0    /* parentIndex/dataLen field length */
  66. #define DIR_OTHER_HI    0x80    /* High bit of ARCH_OTHER_LEN */
  67. #define DIR_OTHER_LO    0x40    /* How bit of ARCH_OTHER_LEN */
  68. #define DIR_SPECIAL        0x20    /* Whether this is a type SPECIAL header */
  69. #define DIR_LINKED        0x10    /* Whether the directory header is linked */
  70. #define DIR_UNICODE        0x08    /* Whether directory name is Unicode */
  71. #define DIR_RESERVED    0x07    /* Reserved for future use */
  72.  
  73. /* The value of the ARCH_OTHER_LEN field */
  74.  
  75. #define ARCH_OTHER_ZERO_ZERO 0x0000                /* Fields: ROOT_DIR, 0 */
  76. #define ARCH_OTHER_BYTE_BYTE ( ARCH_OTHER_LO )    /* Fields: BYTE, BYTE */
  77. #define ARCH_OTHER_BYTE_WORD ( ARCH_OTHER_HI )    /* Fields: BYTE, WORD */
  78. #define ARCH_OTHER_WORD_LONG ( ARCH_OTHER_HI | ARCH_OTHER_LO )/* Fields: WORD, LONG */
  79.  
  80. /* The value of the DIR_OTHER_LEN field */
  81.  
  82. #define DIR_OTHER_ZERO_ZERO    0x00                /* Fields: ROOT_DIR, 0 */
  83. #define DIR_OTHER_BYTE_BYTE    ( DIR_OTHER_LO )    /* Fields: BYTE, BYTE */
  84. #define DIR_OTHER_BYTE_WORD ( DIR_OTHER_HI )    /* Fields: BYTE, WORD */
  85. #define DIR_OTHER_WORD_LONG    ( DIR_OTHER_HI | DIR_OTHER_LO )/* Fields: WORD, LONG */
  86.  
  87. /* The format of the data within the archive.  FORMAT_UNKNOWN must be the
  88.    last entry for a valid file */
  89.  
  90. #define FORMAT_STORED        ( 0 << 6 )
  91. #define FORMAT_PACKED        ( 1 << 6 )
  92. #define FORMAT_UNKNOWN        ( 2 << 6 )
  93.  
  94. /* The OS we are running under. 'OS_UNKNOWN' must always be the last entry. */
  95.  
  96. enum { OS_MSDOS, OS_UNIX, OS_AMIGA, OS_MAC, OS_ARCHIMEDES, OS_OS2, OS_IIGS,
  97.        OS_ATARI, OS_VMS, OS_PRIMOS, OS_UNKNOWN };
  98.  
  99. /****************************************************************************
  100. *                                                                            *
  101. *                              Internal File Headers                            *
  102. *                                                                            *
  103. ****************************************************************************/
  104.  
  105. /* Note that due to the variable length of the headers when written to disk
  106.    the lengths of some fields in these structures may not correspond to the
  107.    actual data on disk */
  108.  
  109. typedef struct {
  110.                LONG fileTime;        /* Date + time of the file */
  111.                LONG fileLen;        /* Original data length */
  112.                LONG dataLen;        /* Archived data length */
  113.                LONG auxDataLen;        /* Auxiliary data field length */
  114.                WORD dirIndex;        /* Where the file is in the dir.tree */
  115.                WORD archiveInfo;    /* File-specific bitflags */
  116.                } FILEHDR;
  117.  
  118. /* The internal directory header */
  119.  
  120. typedef struct {
  121.                LONG dirTime;            /* Date + time of the directory */
  122.                LONG dataLen;            /* Directory data length */
  123.                WORD parentIndex;        /* The parent of this directory */
  124.                BYTE dirInfo;            /* Directory-specific bitflags */
  125.                } DIRHDR;
  126.  
  127. /****************************************************************************
  128. *                                                                            *
  129. *                            Special File/Directory Types                    *
  130. *                                                                            *
  131. ****************************************************************************/
  132.  
  133. /* The types of files with main file type SPECIAL in the archInfo field.
  134.    These and a type ID in the word following the header, giving 65536 types
  135.    of special files */
  136.  
  137. #define TYPE_NORMAL            0            /* Normal file header */
  138. #define TYPE_DUMMY            1            /* Dummy file header */
  139.  
  140. #define TYPE_COMMENT_TEXT    2            /* Comment types */
  141. #define TYPE_COMMENT_ANSI    3
  142. #define TYPE_COMMENT_GIF    4
  143.  
  144. /* The types of directories with the DIR_SPECIAL bit set in the parentIndex
  145.    field */
  146.  
  147. #define DIRTYPE_NORMAL        0            /* Normal directory header */
  148. #define DIRTYPE_DUMMY        1            /* Dummy directory header */
  149.  
  150. /****************************************************************************
  151. *                                                                            *
  152. *                            File Extrainfo Handling                            *
  153. *                                                                            *
  154. ****************************************************************************/
  155.  
  156. /* The defines to handle the extraInfo data:
  157.  
  158. typedef struct {
  159.                unsigned secured     : 1; \* Whether data is secured *\
  160.                unsigned encrypted   : 1; \* Whether data is encrypted *\
  161.                unsigned linked        : 1; \* Whether file is linked *\
  162.                unsigned unicode     : 1; \* Whether filename is Unicode *\
  163.                unsigned extraLength : 4; \* Length of extraInfo field *\
  164.                } EXTRAINFO; */
  165.  
  166. #define EXTRALEN_MASK        0x0F        /* Length field of extraInfo byte */
  167.  
  168. #define getExtraInfoLen(x)    ( x & EXTRALEN_MASK )
  169.  
  170. #define EXTRA_SECURED        0x80        /* isSecured bit */
  171. #define EXTRA_ENCRYPTED        0x40        /* isEncrypted bit */
  172. #define EXTRA_LINKED        0x20        /* isLinked bit */
  173. #define EXTRA_UNICODE        0x10        /* isUnicode bit */
  174.  
  175. /****************************************************************************
  176. *                                                                            *
  177. *                                Link Handling                                *
  178. *                                                                            *
  179. ****************************************************************************/
  180.  
  181. /* Defines to handle links */
  182.  
  183. #define LINK_ANCHOR            0x8000        /* Link is an anchor node */
  184.  
  185. #define isLinkAnchor(x)        ( x & LINK_ANCHOR )
  186. #define getLinkID(x)        ( x & ~LINK_ANCHOR )
  187.  
  188. #endif /* _FILEHDR_DEFINED */
  189.